package com.lmaos.basetools.queue3;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class AsyncQueue3Factory {
	
	private static AsyncQueue3 defaultAsyncQueue3 = new AsyncQueue3Proxy(new ThreadPoolExecutor(20, 50, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(1000)));
	
	public static void setDefaultAsyncResultCallback(AsyncResultCallback asyncResultCallback){
		defaultAsyncQueue3.setAsyncResultCallback(asyncResultCallback);
	}
	
	public static void setDefaultAsyncResultCallback(Class clazz,AsyncResultCallback asyncResultCallback){
		defaultAsyncQueue3.addAsyncResultCallback(clazz, asyncResultCallback);
	}
	/** 获得异步代理bean，方法被@Async修饰的将进行异步处理
	 * 
	 * @param clazz
	 * @return
	 */
	public static <T>T getDefaultAsyncBean(Class<T> clazz){
		return defaultAsyncQueue3.getBean(clazz);
	}
	
	public static AsyncQueue3 getAsyncQueue3(ThreadPoolExecutor threadPoolExecutor,AsyncResultCallback asyncResultCallback) {
		AsyncQueue3 asyncQueue3 = new AsyncQueue3Proxy(threadPoolExecutor);
		asyncQueue3.setAsyncResultCallback(asyncResultCallback);
		return asyncQueue3;
	}
	@Async("x")
	public void x(){
	}
	public static void main(String[] args) throws InterruptedException {
		try {
			getDefaultAsyncBean(AsyncQueue3Factory.class).x();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		Thread.sleep(100);
		defaultAsyncQueue3.close();
	}
}
